﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
using System.Collections.Generic;
using Web.Controls;
using Platform.Common;
using Platform.Menu;
using Platform.Data;

namespace Web
{
    public partial class Master : System.Web.UI.MasterPage
    {
        #region 私有变量

        public static int RootMenuID = Convert.ToInt32(ConfigurationManager.AppSettings["RootMenuID"]);
        public static int firstCount = Convert.ToInt32(ConfigurationManager.AppSettings["FirstMenuCount"]);
        public static int secondCount = Convert.ToInt32(ConfigurationManager.AppSettings["SecondMenuCount"]);
        public static int otherCount = Convert.ToInt32(ConfigurationManager.AppSettings["OtherMenuCount"]);
        public static int LeftChoice = Convert.ToInt32(ConfigurationManager.AppSettings["LeftChoice"]);
        //2级菜单的实际个数,判断leftcontrol上下滚动图片是否显示
        public int secondMaxCount = 0;
        public System.Web.UI.UserControl _LeftControl;

        #endregion

        /// <summary>
        /// 左边菜单控件
        /// </summary>
        public System.Web.UI.UserControl LeftControl
        {
            get
            {
                if (_LeftControl == null)
                {
                    if (LeftChoice == 0)
                    {
                        _LeftControl = (System.Web.UI.UserControl)LoadControl("~/Controls/PopLeftUserControl.ascx");
                    }
                    else
                    {
                        _LeftControl = (System.Web.UI.UserControl)LoadControl("~/Controls/LeftMenuControl.ascx");
                    }
                }
                return _LeftControl;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            TitleMenu.OnChange += new EventHandler(ReBindData);
            if (!IsPostBack)
            {
                leftPannel.Controls.Add(LeftControl);
            }
        }

        protected void ReBindData(object sender, EventArgs e)
        {
   
            leftPannel.Controls.Add(LeftControl);
            if (LeftChoice == 0)
            {
                ((PopLeftUserControl)LeftControl).BindSecondMenuID((int)sender);
                secondMaxCount = Web.Controls.PopLeftUserControl.sMaxCount;
            }
            else
            {
                ((LeftMenuControl)LeftControl).BindSecondMenu((int)sender);
                secondMaxCount = Web.Controls.LeftMenuControl.sMaxCount;
            }
        }
    }
}
